package br.com.rapidrest.chain;

import br.com.rapidrest.exception.ChainException;
import br.com.rapidrest.request.RequestScope;

public class BeanCommand implements Command {

	public static final String DEFAULT_INIT_METHOD = "init";

	public static final String PAGE_BEAN_SESSION_SUFFIX = "rapidrest.";

	@Override
	public void execute(Chain chain) throws ChainException {
		BasicChainContext context = (BasicChainContext) chain.getContext();
		RequestScope requestScope = context.getRequestScope();

		Class<?> beanClass = requestScope.getBeanClass();

		Object bean = null;

		try {
			bean = beanClass.newInstance();
		} catch (InstantiationException e) {
			throw new ChainException(e);
		} catch (IllegalAccessException e) {
			throw new ChainException(e);
		}
		context.setBean(bean);

		chain.proceed();
	}

}